﻿<!--1、版本号要与nuget包一致；2、id不能为空-->
<script async="async" id="mini-profiler" src="/mini-profiler-resources/includes.min.js?v=4.2.22+4563a9e1ab" data-version="4.2.22+4563a9e1ab" data-path="/mini-profiler-resources/" data-current-id="f6b88311-015a-44ed-bde0-cdab4c2d0d9b" data-ids="ac204d24-e2df-486e-a135-8167336643b7,f6b88311-015a-44ed-bde0-cdab4c2d0d9b" data-position="Left" data-scheme="Light" data-authorized="true" data-max-traces="15" data-toggle-shortcut="Alt+P" data-trivial-milliseconds="2.0" data-ignored-duplicate-execute-types="Open,OpenAsync,Close,CloseAsync"></script>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>%(DocumentTitle)</title>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700"
          rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="./swagger-ui.css">
    <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
    <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
    <style>
        html {
            box-sizing: border-box;
            overflow: -moz-scrollbars-vertical;
            overflow-y: scroll;
        }

        *,
        *:before,
        *:after {
            box-sizing: inherit;
        }

        body {
            margin: 0;
            background: #fafafa;
        }
    </style>
    %(HeadContent)
</head>

<body>
    <div id="swagger-ui"></div>
    <script src="/layuiAdmin/modules/crypto-js.min.js"></script>
    <script src="swagger-ui-bundle.js"></script>
    <script src="swagger-ui-standalone-preset.js"></script>
    <script>
        var auth = window.auth || {};
        auth.tokenCookieName = "aspnetcore.authauth";
        auth.loginUrl = () => top.location.pathname.split('/doc')[0] + "/api/Login/Login";
        auth.logoutUrl = () => top.location.pathname.split('/doc')[0] + "/api/Login/Logout";

        auth.logout = function (callback) {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        var res = JSON.parse(xhr.responseText);
                        if (res.code !== 200) {
                            console.warn(res.msg);
                            return;
                        }
                    }
                    sessionStorage.removeItem("auth.token");
                    sessionStorage.removeItem("auth.hasLogin");
                    callback();
                }
            };
            xhr.open('Get', auth.logoutUrl(), true);
            xhr.send();
        }
        auth.hasLogin = function () {
            return sessionStorage.getItem("auth.hasLogin");
        }
        auth.openAuthDialog = function (loginCallback) {
            auth.closeAuthDialog();
            var authAuthDialog = document.createElement('div');
            authAuthDialog.className = 'dialog-ux';
            authAuthDialog.id = 'auth-auth-dialog';
            document.getElementsByClassName("swagger-ui")[1].appendChild(authAuthDialog);
            // -- backdrop-ux
            var backdropUx = document.createElement('div');
            backdropUx.className = 'backdrop-ux';
            authAuthDialog.appendChild(backdropUx);
            // -- modal-ux
            var modalUx = document.createElement('div');
            modalUx.className = 'modal-ux';
            authAuthDialog.appendChild(modalUx);
            // -- -- modal-dialog-ux
            var modalDialogUx = document.createElement('div');
            modalDialogUx.className = 'modal-dialog-ux';
            modalUx.appendChild(modalDialogUx);
            // -- -- -- modal-ux-inner
            var modalUxInner = document.createElement('div');
            modalUxInner.className = 'modal-ux-inner';
            modalDialogUx.appendChild(modalUxInner);
            // -- -- -- -- modal-ux-header
            var modalUxHeader = document.createElement('div');
            modalUxHeader.className = 'modal-ux-header';
            modalUxInner.appendChild(modalUxHeader);
            var modalHeader = document.createElement('h3');
            modalHeader.innerText = 'Authorize';
            modalUxHeader.appendChild(modalHeader);
            // -- -- -- -- modal-ux-content
            var modalUxContent = document.createElement('div');
            modalUxContent.className = 'modal-ux-content';
            modalUxInner.appendChild(modalUxContent);
            modalUxContent.onkeydown = function (e) {
                if (e.keyCode === 13) {
                    //try to login when user presses enter on authorize modal
                    auth.login(loginCallback);
                }
            };

            //Inputs
            createInput(modalUxContent, 'userName', 'Username or email address');
            createInput(modalUxContent, 'password', 'Password', 'password');

            //Buttons
            var authBtnWrapper = document.createElement('div');
            authBtnWrapper.className = 'auth-btn-wrapper';
            modalUxContent.appendChild(authBtnWrapper);

            //Close button
            var closeButton = document.createElement('button');
            closeButton.className = 'btn modal-btn auth btn-done button';
            closeButton.innerText = 'Close';
            closeButton.style.marginRight = '5px';
            closeButton.onclick = auth.closeAuthDialog;
            authBtnWrapper.appendChild(closeButton);

            //Authorize button
            var authorizeButton = document.createElement('button');
            authorizeButton.className = 'btn modal-btn auth authorize button';
            authorizeButton.innerText = 'Login';
            authorizeButton.onclick = function () {
                auth.login(loginCallback);
            };
            authBtnWrapper.appendChild(authorizeButton);
        }
        auth.closeAuthDialog = function () {
            if (document.getElementById('auth-auth-dialog')) {
                document.getElementsByClassName("swagger-ui")[1].removeChild(document.getElementById('auth-auth-dialog'));
            }
        }
        auth.login = function (callback) {
            var usernameOrEmailAddress = document.getElementById('userName').value;
            if (!usernameOrEmailAddress) {
                alert('Username or Email Address is required, please try with a valid value !');
                return false;
            }

            var password = document.getElementById('password').value;
            if (!password) {
                alert('Password is required, please try with a valid value !');
                return false;
            }
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        var res = JSON.parse(xhr.responseText);
                        if (res.code !== 200) {
                            alert(res.msg);
                            return;
                        }
                        sessionStorage.setItem("auth.token", res.data.auth_token.token);
                        sessionStorage.setItem("auth.hasLogin", true);
                        callback();
                    } else {
                        alert('Login failed !');
                    }
                }
            };
            xhr.open('POST', auth.loginUrl(), true);
            xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            xhr.send("username=" + encodeURIComponent(usernameOrEmailAddress) + "&password=" + CryptoJS.MD5(password).toString());
        }
        function createInput(container, id, title, type) {
            var wrapper = document.createElement('div');
            wrapper.className = 'wrapper';
            container.appendChild(wrapper);
            var label = document.createElement('label');
            label.innerText = title;
            wrapper.appendChild(label);
            var section = document.createElement('section');
            section.className = 'block-tablet col-10-tablet block-desktop col-10-desktop';
            wrapper.appendChild(section);
            var input = document.createElement('input');
            input.id = id;
            input.type = type ? type : 'text';
            input.style.width = '100%';
            section.appendChild(input);
        }


    </script>
    <script>
        window.onload = function () {
            if (top.location.pathname.indexOf("swagger") > -1) {
                //未指定RoutePrefix
                auth.loginUrl = () => top.location.pathname.split('/index.html')[0] + "/api/Login/Login";
                auth.logoutUrl = () => top.location.pathname.split('/swagger')[0] + "/api/Login/Logout";
            } else {
                //指定RoutePrefix 判断倒数第二个斜杠
                const lastSlashIndex = top.location.pathname.lastIndexOf('/');
                const secondLastSlashIndex = top.location.pathname.substring(0, lastSlashIndex - 1);
                auth.loginUrl = () => top.location.pathname.substring(0, secondLastSlashIndex) + "/api/Login/Login";
                auth.logoutUrl = () => top.location.pathname.substring(0, secondLastSlashIndex) + "/api/Login/Logout";
            }

            var configObject = JSON.parse('%(ConfigObject)');
            // Apply mandatory parameters
            configObject.dom_id = "#swagger-ui";
            configObject.presets = [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset];
            configObject.layout = "StandaloneLayout";
            configObject.requestInterceptor = function (request) {
                request.headers['Authorization'] = 'Bearer ' + sessionStorage.getItem("auth.token");
                return request;
            };
            if (!configObject.hasOwnProperty("oauth2RedirectUrl")) {
                configObject.oauth2RedirectUrl = window.location + "oauth2-redirect.html"; // use the built-in default
            }
            function getAuthorizeButtonText() {
                return auth.hasLogin() ? 'Logout' : 'Authorize';
            }
            function getAuthorizeButtonCssClass() {
                return auth.hasLogin() ? 'cancel' : 'authorize';
            }
            configObject.plugins = [
                function (system) {
                    return {
                        components: {
                            authorizeBtn: function () {
                                return system.React.createElement("button",
                                    {
                                        id: "authorize",
                                        className: "btn " + getAuthorizeButtonCssClass(),
                                        style: {
                                            lineHeight: "normal"
                                        },
                                        onClick: function () {
                                            var authorizeButton = document.getElementById('authorize');
                                            auth.logout(function () {
                                                authorizeButton.innerText = getAuthorizeButtonText();
                                                authorizeButton.className = 'btn ' + getAuthorizeButtonCssClass();
                                            });
                                            if (!auth.hasLogin()) {
                                                auth.openAuthDialog(function () {
                                                    authorizeButton.innerText = getAuthorizeButtonText();
                                                    authorizeButton.className = 'btn ' + getAuthorizeButtonCssClass();
                                                    auth.closeAuthDialog();
                                                });
                                            }
                                        }
                                    }, getAuthorizeButtonText());
                            }
                        }
                    }
                }
            ];
            // Build a system
            SwaggerUIBundle(configObject);
        }</script>
</body>

</html>